<template>
	<view class="">
		<view class="view-center" style="justify-content: center;">
			<view @click="clickTagTabs(1)">
				<view :class="tagTab==1?'tagTab-tv':'tagTab-tv2'">服务权益</view>
				<view style="width: 130rpx;display: flex;align-items: center;justify-content: center;">
					<view :class="tagTab==1?'line-tv':'line-tv2'"></view>
				</view>

			</view>
			<view style="margin-left: 96rpx;" @click="clickTagTabs(2)">
				<view :class="tagTab==2?'tagTab-tv':'tagTab-tv2'">我的订单</view>
				<view style="width: 130rpx;display: flex;align-items: center;justify-content: center;">
					<view :class="tagTab==2?'line-tv':'line-tv2'"></view>
				</view>

			</view>
		</view>

		<view :style="{height: windowHeight}" style="margin-top: 120rpx;" v-if="serveList.length>0 && tagTab==1">

			<view v-for="(item,index) in serveList" :key="index" style="margin-top: 24rpx;">
				<view class="item1">
					<image src="../../../../../static/phone/mine_serve_bg.png" style="width: 686rpx;height: 224rpx;"
						mode="scaleToFill"></image>
				</view>
				<view class="item1" style="margin-top: -224rpx;">
					<view class="item1-left">
						<view class="item1-left-top">
							<text :class="item.status.code==1 ? 'item1-left-top1':'item1-left-top2'">
								<text v-if="item.totalCount==-1">不限</text>
								<text v-if="item.totalCount!=-1">{{item.totalCount-item.usedCount}}</text>
								次</text>
						</view>
						<view class="item1-left-center">
							剩余咨询数
						</view>
						<view class="item1-left-center" style="color: #666666;margin-top: 4rpx;font-size: 18rpx;">
							（{{item.endTimes}}到期）
						</view>
					</view>


					<view class="item1-center">
						<view class="item1-center1">
							<text>关联客户：</text>
							<text>{{item.custName}}</text>
						</view>
						<view class="item1-center2">
							<text class="item1-center21"></text>
							<text style="margin-left: 4rpx;">可发起咨询数：</text>
							<text>
								<text v-if="item.totalCount==-1">不限</text>
								<text v-if="item.totalCount!=-1">{{item.totalCount-item.usedCount}}</text>
								次</text>
						</view>
						<view class="item1-center2">
							<text class="item1-center21"></text>
							<text style="margin-left: 4rpx;">可咨询领域：</text>
							<text>{{item.domainDict==-1 ? '不限':item.domainDict}}</text>
						</view>
						<view class="item1-center2">
							<text class="item1-center21"></text>
							<text style="margin-left: 4rpx;">限制每{{item.cycleValue}}{{item.cycleUnit.desc}}只可咨询
								<text>{{item.cycleTimes == -1 ? '不限':item.cycleTimes}}</text>
								次</text>

						</view>
					</view>

					<view class="item1-right">
						<view class="item1-right1" v-if="item.status.code==1" @click="goInitiated(item)">
							<view>
								<view style="display: flex;align-items: center;justify-content: center;">发</view>
								<view style="display: flex;align-items: center;justify-content: center;">起</view>
								<view style="display: flex;align-items: center;justify-content: center;">咨</view>
								<view style="display: flex;align-items: center;justify-content: center;">询</view>
							</view>

						</view>

						<image v-if="item.status.code==2" :src="mine_serve_old"
							style="width: 112rpx;height: 84rpx;margin-right: 8rpx;"></image>
						<image v-if="item.status.code==3" :src="mine_serve_cancel"
							style="width: 112rpx;height: 84rpx;margin-right: 8rpx;"></image>
					</view>

				</view>

			</view>
		</view>

		<view :style="{height: windowHeight}" style="margin-top: 120rpx;" v-if="orderList.length>0 && tagTab==2">
			<view v-for="(item,index) in orderList" :key="index" style="margin-top: 24rpx;">
				<view class="list-item" @click="goOrderDetail(item)">
					<view class="list-item-l">
						<image :src="item.picUrlsImage" mode="scaleToFill" style="width: 176rpx;height: 176rpx;" />
						<view style="height: 176rpx;margin-left: 20rpx;width: 426rpx;">
							<text class="list-item-title">{{item.goodsName}}</text>
							<view style="margin-top: 16rpx;">
								<text class="list-item-c1">关联客户： <text class="list-item-c2">{{item.custName}}</text>
								</text>
							</view>
							
							<view style="margin-top: 30rpx;display: flex;align-items: center;" v-if="item.status.code==='0'">
								<!-- <view class=""> -->
									<!-- <text style="color: #F35C22;font-size: 28rpx;">¥</text>
									<text style="color: #F35C22;font-size: 40rpx;font-weight: 600;">0.01</text> -->
								<!-- </view> -->
								
								<view class="list-item-buy">
									待支付
								</view>
							</view>

						</view>
					</view>
				</view>
			</view>

		</view>



		<view :style="{height:windowHeight}"
			v-if="(tagTab==1 && serveList.length==0) || (tagTab==2 && orderList.length==0)"
			style="display: flex;align-items: center;justify-content: center;">
			<view>
				<view style="display: flex;align-items: center;justify-content: center;">
					<image :src="no_data" style="width: 300rpx;height: 300rpx;"></image>
				</view>
				<view style="display: flex;align-items: center;justify-content: center;">
					<text style="font-weight: 400;color: #333333;font-size: 28rpx;">暂无数据</text>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	let app = ''
	import verify from '@/pages/utils/verifyUtils.js'
	export default {
		data() {
			return {
				role: '',
				roleUrl: '',

				tagTab: 1, //1 服务权益  2 我的订单
				windowHeight: 0,
				serveList: [], //服务权益列表
				orderList: [], //我的订单列表
				serveTotal: 0,
				orderTotal: 0,

				page: 1,
				mine_serve_old: getApp().globalData.baseImageUrl + '/mine_serve_old.png',
				mine_serve_cancel: getApp().globalData.baseImageUrl + '/mine_serve_cancel.png',

				no_data: getApp().globalData.baseImageUrl + '/no-data.png',
			}
		},
		onLoad() {
			let _this = this
			app = getApp()
			_this.role = app.globalData.role
			_this.roleUrl = _this.$roleUrl({
				tab: _this.role
			})
			_this.windowHeight = (app.globalData.windowHeight - 60) * 2 + 'rpx'

		},
		onShow() {
			this.serveList = []
			this.orderList = []
			this.page = 1
			if (this.tagTab == 1) {
				this.getServeList()
			} else if (this.tagTab == 2) {
				this.getOrderList()
			}
		},
		onPullDownRefresh() {
			this.page = 1
			if (this.tagTab == 1) {
				this.serveList = []
				this.getServeList()
			} else if (this.tagTab == 2) {
				this.orderList = []
				this.getOrderList()
			}
		},
		onReachBottom() {
			console.log('到底啦')
			if (this.tagTab == 1) {
				if (this.serveList.length == this.serveTotal) {
					uni.showToast({
						title: '暂无更多数据',
						icon: 'none'
					})
					return
				}
				this.page = this.page + 1
				this.getServeList()
			} else {
				if (this.orderList.length == this.orderTotal) {
					uni.showToast({
						title: '暂无更多数据',
						icon: 'none'
					})
					return
				}
				this.page = this.page + 1
				this.getOrderList()
			}
		},
		mounted() {

		},
		methods: {
			clickTagTabs(val) {

				this.tagTab = val
				this.page = 1
				if (this.tagTab == 1) {
					this.serveList = []
					this.serveTotal = 0
					this.getServeList()
				} else if (this.tagTab == 2) {
					this.orderList = []
					this.orderTotal = 0
					this.getOrderList()
				}
			},

			async getServeList() {
				let _this = this
				let data = {
					page: _this.page,
					size: 10
				}
				const res = await _this.$myRequest({
					url: "/client/customerRights/list",
					method: 'POST', //默认是GET
					data: data
				})
				console.log('服务权限列表', res)
				if (res.data.code == 200) {
					let list = res.data.data.list
					for (var i = 0; i < list.length; i++) {
						let endTimes = list[i]['endTime']
						if (verify.isNotEmpty(endTimes)) {
							endTimes = endTimes.substring(0, 11)
						}
						list[i]['endTimes'] = endTimes
						_this.serveList.push(list[i])
					}
					if (_this.page === 1) {
						_this.serveTotal = res.data.data.count
					}


				}
			},

			async getOrderList() {
				let _this = this
				let data = {
					page: _this.page,
					size: 10
				}
				const res = await _this.$myRequest({
					url: "/client/goodsOrder/list",
					method: 'POST', //默认是GET
					data: data
				})
				console.log('订单列表', res)
				if (res.data.code == 200) {
					let list = res.data.data.list
					for (var i = 0; i < list.length; i++) {
						// if(list[i]['status']['code']!='0'){
						// 	let item = list[i]
						// 	item.picUrlsImage = _this.$imageUrls({
						// 		picUrls: item.picUrls
						// 	})
						// 	_this.orderList.push(item)
						// }
						let item = list[i]
						item.picUrlsImage = _this.$imageUrls({
							picUrls: item.goodsPicUrls
						})
						_this.orderList.push(item)
						
					}
					if (_this.page === 1) {
						_this.orderTotal = res.data.data.count
					}
				}
			},

			/**
			 * 发起咨询
			 */
			goInitiated(val) {
				uni.navigateTo({
					url: '../../initiatedConsult/initiatedConsult?from=add'
				})
			},

			/**
			 * 前往订单详情
			 */
			goOrderDetail(item) {
				let id = item.id
				uni.navigateTo({
					url: './orderDetail?id=' + id
				})
			},
		}
	}
</script>

<style>
	page {
		background-color: #f7f7f7;
	}
</style>

<style scoped lang="scss">
	.view-center {
		position: fixed;
		top: 0;
		width: 100%;
		height: 88rpx;
		background: #FFFFFF;
		box-shadow: 0px 4rpx 8rpx 0px rgba(0, 0, 0, 0.0600);
		display: flex;
		align-items: center;
		font-size: 32rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		color: #333333;
	}

	.line-tv {
		width: 80rpx;
		height: 4rpx;
		background: #2DA9C5;
		margin-top: 5rpx;
	}

	.line-tv2 {
		margin-top: 5rpx;
		width: 80rpx;
		height: 4rpx;
		background: #ffffff;
		margin-top: 5rpx;
	}

	.tagTab-tv {
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 32rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		color: #333333;
	}

	.tagTab-tv2 {
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 32rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 400;
		color: #999999;
	}

	.item1 {
		width: 686rpx;
		height: 224rpx;
		margin-left: 32rpx;
		display: flex;
		align-items: center;
	}

	.item1-left {
		width: 195rpx;
		margin-left: 2rpx;
	}

	.item1-left-top {
		width: 195rpx;
		font-size: 48rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.item1-left-top1 {
		color: #FF6132;
	}

	.item1-left-top2 {
		color: #999999;
	}

	.item1-left-center {
		width: 195rpx;
		font-size: 20rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #999999;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.item1-right {
		margin-left: auto;

	}

	.item1-right1 {
		width: 64rpx;
		height: 176rpx;
		background: #2DA9C5;
		border-radius: 4rpx;
		color: #ffffff;
		font-size: 28rpx;
		margin-right: 24rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.item1-center1 {
		font-size: 24rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		color: #333333;
	}

	.item1-center2 {
		font-size: 20rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #999999;
		display: flex;
		align-items: center;
		margin-top: 8rpx;
	}

	.item1-center21 {
		width: 8rpx;
		height: 8rpx;
		background: #8ED8E9;
		border-radius: 8rpx;

	}

	.list-item {
		width: 686rpx;
		margin-left: 32rpx;
		height: 240rpx;
		background-color: white;
		margin-top: 24rpx;
		display: flex;
		align-items: center;
	}

	.list-item-l {
		height: 176rpx;
		display: flex;
		align-items: center;
		margin-left: 32rpx;
		margin-right: 32rpx;
	}

	.list-item-title {
		font-size: 28rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		color: #333333;
		line-height: 40rpx;
	}

	.list-item-c1 {
		font-size: 24rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #999999;
		line-height: 34rpx;
		margin-top: 16rpx;
	}

	.list-item-c2 {
		color: #333333;
	}
	
	.list-item-buy{
		width: 143rpx;
		height: 56rpx;
		background-color: #E8F7FB;
		margin-left: auto;
		border-radius: 56rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #2DA9C5;
	}
</style>
